/**
 * 
 */
package com.zhaoyan.service;

import static org.junit.Assert.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import com.bot.utils.FileUtils;
import com.zhaoyan.entity.Order;

/**
 * @author zhaoyan
 *
 * 2020年2月10日
 */
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:spring-beans.xml")
public class ImportOrderFile {

	
	@Autowired
	private OrderService orderService;
	
	
	@Test
	public void test() throws IOException, ParseException {
	
		String file = FileUtils.class.getClassLoader().getResource("order.txt").getFile();
		
		List<String> readLines = FileUtils.readLines(file);
		
		for (String string : readLines) {
			
			String[] split = string.split(",");
			
			Order order = new Order();
			
			//08159,05361,00003,01,北极绒 羽绒服2,1,0,4,13,608,322,bei001北极绒 羽绒服2,2,0014,0109,2019-12-12 12:37:08,2019-12-12 12:37:08,1,2019-12-12 12:37:08,1,1,13614262991
//			new Order(id, , order_sn, member_id, supplier_id, supplier_name, 
//					order_status, after_status, product_count, product_amount_total, 
//					order_amount_total, logistics_fee, address_id, pay_channel, 
//					out_trade_no, escrow_trade_no, pay_time, delivery_time, 
//					order_settlement_status, order_settlement_time, is_package, 
//					is_integral, telphone, updated_at, deleted_at);
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd MM:hh:ss");
			order.setOrder_no(split[0]);
			order.setOrder_sn(split[1]);
			order.setMember_id(Integer.parseInt(split[2]));
			order.setSupplier_id(Integer.parseInt(split[3]));
			order.setSupplier_name(split[4]);
			order.setOrder_status(Integer.parseInt(split[5]));
			order.setAfter_status(Integer.parseInt(split[6]));
			order.setProduct_count(Integer.parseInt(split[7]));
			order.setProduct_amount_total(new BigDecimal(Double.parseDouble(split[8])));
			order.setOrder_amount_total(new BigDecimal(Double.parseDouble(split[9])));
			order.setLogistics_fee(new BigDecimal(Double.parseDouble(split[10])));
			order.setAddress_id(split[11]);
			order.setPay_channel(Integer.parseInt(split[12]));
			order.setOut_trade_no(split[13]);
			order.setEscrow_trade_no(split[14]);
			order.setPay_time(sdf.parse(split[15]));
			order.setDelivery_time(sdf.parse(split[16]));
			order.setOrder_settlement_status(Integer.parseInt(split[17]));
			order.setOrder_settlement_time(sdf.parse(split[18]));
			
			order.setIs_package(split[19]);
			order.setIs_integral(split[20]);
			
			order.setTelphone(split[21]);
			
			System.out.println(order);
			
			orderService.addOrder(order);
			
			
		}
		
		
	}

}

